package util;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.laoxinwen.app.R;

/**
 * Created by ilioili on 2015/3/31.
 */
public class DialogUtil {
    public static Dialog getConfirmDialog(Activity activity, String title, String msg, final CallBack callBack) {
        final Dialog dialog = new Dialog(activity);
        dialog.setCancelable(true);
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_confirm);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.getWindow().findViewById(R.id.bt_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.onCallBack();
                dialog.dismiss();
            }
        });
        dialog.getWindow().findViewById(R.id.bt_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        TextView tvTitle = (TextView) dialog.getWindow().findViewById(R.id.tv_title);
        tvTitle.setText(title);
        TextView tvMsg = (TextView) dialog.getWindow().findViewById(R.id.tv_msg);
        tvMsg.setText(msg);
        return dialog;
    }

    public interface CallBack {
        void onCallBack();
    }

}
